package top.healthylife.gateway.platform.fh.api.api.haiguan;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import top.healthylife.gateway.core.service.ParentFace;
import top.healthylife.gateway.dto.annotation.ApiServiceExplain;
import top.healthylife.gateway.platform.fh.api.api.IUnifyHandler;
import top.healthylife.gateway.platform.fh.api.util.FhHttpUtil;
import top.healthylife.gateway.platform.fh.dto.haiguan.businessquery.req.FhReqBusinessQueryCustomsDto;
import top.healthylife.gateway.platform.fh.dto.haiguan.businessquery.res.FhResBusinessQueryCustomsDto;

/**
 * @author : GaoZeXi
 * @date 2021/11/1 11:17
 */
@Slf4j
@Service
@ApiServiceExplain(price = 20, apiName = "海关数据高精版-企业查询", docUrl = "-", info = "海关数据高精版-企业查询-数据类型:custom_qy,custom_xuke,custom_credit,custom_punish")
public class FhBusinessQueryCustomsApi implements ParentFace<FhReqBusinessQueryCustomsDto, FhResBusinessQueryCustomsDto>, IUnifyHandler {
    private static final String DOMAIN = "query/custom";

    @Override
    public FhResBusinessQueryCustomsDto execute(FhReqBusinessQueryCustomsDto t) {
        t.checkDataType();
        JSONObject jsonObject = FhHttpUtil.HttpRequest(t, DOMAIN);
        if (jsonObject == null) {
            return new FhResBusinessQueryCustomsDto();
        }
        if (StrUtil.isBlank(t.getDataType())) {
            return fillAllFields(jsonObject, t,FhResBusinessQueryCustomsDto.class);
        } else {
            return  fillFieldsByDataType(jsonObject, t,FhResBusinessQueryCustomsDto.class);
        }
    }

}
